from dataclasses import dataclass
from typing import Any, TypeVar, Type, cast


T = TypeVar("T")


def from_str(x: Any) -> str:
    assert isinstance(x, str)
    return x


def to_class(c: Type[T], x: Any) -> dict:
    assert isinstance(x, c)
    return cast(Any, x).to_dict()


@dataclass
class Body:
    """主体数据"""

    team: str
    """代表队/代表团/俱乐部"""

    athlete_name: str
    """运动员姓名"""

    athlete_bib: str
    """运动员号码"""

    athlete_telephone: str
    """运动员联系方式"""

    result_a: str
    """A线成绩"""

    result_b: str
    """B线成绩"""

    rank: str
    """排名"""

    @staticmethod
    def from_dict(obj: Any) -> 'Body':
        assert isinstance(obj, dict)
        team = from_str(obj.get("Team"))
        athlete_name = from_str(obj.get("AthleteName"))
        athlete_bib = from_str(obj.get("AthleteBib"))
        athlete_telephone = from_str(obj.get("AthleteTelephone"))
        result_a = from_str(obj.get("ResultA"))
        result_b = from_str(obj.get("ResultB"))
        rank = from_str(obj.get("Rank"))
        return Body(team, athlete_name, athlete_bib, athlete_telephone, result_a, result_b, rank)

    def to_dict(self) -> dict:
        result: dict = {}
        result["Team"] = from_str(self.team)
        result["AthleteName"] = from_str(self.athlete_name)
        result["AthleteBib"] = from_str(self.athlete_bib)
        result["AthleteTelephone"] = from_str(self.athlete_telephone)
        result["ResultA"] = from_str(self.result_a)
        result["ResultB"] = from_str(self.result_b)
        result["Rank"] = from_str(self.rank)
        return result


@dataclass
class Head:
    """头部数据"""

    device_id: str
    """设备Id"""

    message_uuid: str
    """消息Uuid"""

    timestamp: str
    """发送消息的时间。格式：yyyy-MM-dd HH:mm:ss.fff 比如：2020-09-02 12:24:09.923"""

    message_type: str
    """消息类型"""

    @staticmethod
    def from_dict(obj: Any) -> 'Head':
        assert isinstance(obj, dict)
        device_id = from_str(obj.get("DeviceId"))
        message_uuid = from_str(obj.get("MessageUuid"))
        timestamp = from_str(obj.get("Timestamp"))
        message_type = from_str(obj.get("MessageType"))
        return Head(device_id, message_uuid, timestamp, message_type)

    def to_dict(self) -> dict:
        result: dict = {}
        result["DeviceId"] = from_str(self.device_id)
        result["MessageUuid"] = from_str(self.message_uuid)
        result["Timestamp"] = from_str(self.timestamp)
        result["MessageType"] = from_str(self.message_type)
        return result


@dataclass
class RealResult:
    """实时成绩"""

    head: Head
    """头部数据"""

    body: Body
    """主体数据"""

    @staticmethod
    def from_dict(obj: Any) -> 'RealResult':
        assert isinstance(obj, dict)
        head = Head.from_dict(obj.get("Head"))
        body = Body.from_dict(obj.get("Body"))
        return RealResult(head, body)

    def to_dict(self) -> dict:
        result: dict = {}
        result["Head"] = to_class(Head, self.head)
        result["Body"] = to_class(Body, self.body)
        return result


def real_result_from_dict(s: Any) -> RealResult:
    return RealResult.from_dict(s)


def real_result_to_dict(x: RealResult) -> Any:
    return to_class(RealResult, x)
